namespace org.jawk.util
{
	/// <summary>A stack implemented with an ArrayList.</summary>
	/// <remarks>
	/// A stack implemented with an ArrayList.  Unlike the java.util.Stack
	/// which uses a java.util.Vector as a storage mechanism,
	/// this implementation is non-synchronized to improve performance.
	/// <p>
	/// It performs quicker than the LinkedListStackImpl version.
	/// <p>
	/// There is no maximum capacity which is enforced, nor is there any
	/// checks if pop() is executed on an empty stack.
	/// </remarks>
	[System.Serializable]
	public class ArrayStackImpl<E> : System.Collections.Generic.List<E>, org.jawk.util.IMyStack<E>
	{
		/// <summary>Allocates an ArrayList with a capacity of 100.</summary>
		/// <remarks>Allocates an ArrayList with a capacity of 100.</remarks>
		public ArrayStackImpl() : base(100)
		{
		}

		/// <summary>Push an item to the stack.</summary>
		/// <remarks>Push an item to the stack.</remarks>
		/// <param name="o">The item to push onto the stack.</param>
		public virtual void Push(E o)
		{
			Add(o);
		}

		/// <summary>Pops an item off the stack.</summary>
		/// <remarks>
		/// Pops an item off the stack.
		/// <p>
		/// Warning: no checks are done in terms of size, etc.
		/// If a pop() occurrs on an empty stack,
		/// an ArrayIndexOutOfBoundException is thrown.
		/// </remarks>
		/// <returns>
		/// The top of the stack.  The element is subsequently
		/// removed from the stack.
		/// </returns>
		public virtual E Pop()
		{
            E elt = this[Count - 1];
			RemoveAt(Count - 1);
            return elt;
		}

		public virtual E Peek()
		{
			return this[Count - 1];
		}

        

        public int Size()
        {
            return Count;
        }

        
    }
}
